package at.mri.dogwatch.server.model.dao;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import at.mri.dogwatch.server.model.Video;

import com.google.gwt.dev.util.Preconditions;
import com.googlecode.objectify.Query;

public class VideoDao extends ObjectifyDao<Video> {
	private static final int MIN_COUNT = 5;

	public List<Video> listLastModified(int count){
		Query<Video> videoQuery = ofy().query(Video.class).order("-lastModifiedDate").limit(Math.min(count, MIN_COUNT));
		ArrayList<Video> result = new ArrayList<Video>(count);
		
		for (Video video : videoQuery) {
			result.add(video);
		}
		return result;
	}
	
	
	
	public void save(Video video){
		Date now = new Date();
		video.setLastModifiedDate(now);
		video.setCreatedDate(now);
		put(video);
	}
}
